package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.WorkflowBusinessNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2019-08-01 15:48:37
 */
@Repository
public class WorkflowBusinessNodeDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(WorkflowBusinessNodeDao.class);

    public WorkflowBusinessNode insert(final WorkflowBusinessNode workflowBusinessNode) {
        insert("WorkflowBusinessNode.insert", workflowBusinessNode);
        return workflowBusinessNode;
    }

    public Boolean updateInfoById(final WorkflowBusinessNode workflowBusinessNode) {
        return update("WorkflowBusinessNode.updateInfoById", workflowBusinessNode) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("WorkflowBusinessNode.updateInfoByQuery", query) > 0;
    }

    public WorkflowBusinessNode selectById(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return queryForObject("WorkflowBusinessNode.selectById", query);
    }

    public List<WorkflowBusinessNode> selectByQuery(final Query query) {
        return queryForList("WorkflowBusinessNode.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("WorkflowBusinessNode.countByQuery", query);
    }

    public Boolean deleteById(final Integer id) {
        WorkflowBusinessNode workflowBusinessNode = new WorkflowBusinessNode();
        workflowBusinessNode.setDeleteFlag(1);
        workflowBusinessNode.setId(id);

        return update("WorkflowBusinessNode.updateInfoById", workflowBusinessNode) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Long id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("WorkflowBusinessNode.deleteById", query) > 0;
    }
}